//3．编写一个函数，接受一个int类型的参数，并返回该参数中打开位的数量。在一个程序中测试该函数。
#include <stdio.h>
#include <string.h>

int count_open_bit_in_int(int val);

int main() {
    int val = 0xcc;
    printf("%d has open bits is %d", val, count_open_bit_in_int(val));
    return 0;
}
int count_open_bit_in_int(int val) {
    size_t s_i = sizeof(int);
    int bits = (int) s_i * 8;
    int mask = 1;
    int count = 0;
    for (int i = 0; i < bits; ++i) {
        if (val >> i & mask) {
            count++;
        }
    }
    return count;
}